package mulMan.domain;

import java.util.Observable;
import java.util.Observer;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import mulMan.services.AudioFileServices;

public class AudioFileModel extends Observable implements Observer{
	
	private AudioFile audioFile;
	private AudioFileServices audioFileServices;
	
	public AudioFileModel() {
		audioFile = new AudioFile();
		audioFile.addObserver(this);
		
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"application-context.xml");
		audioFileServices = (AudioFileServices) context.getBean("audioFileServices");
	}
	

	public AudioFile getAudioFile() {
		return audioFile;
	}
	public void setAudioFile(AudioFile audioFile) {
		this.audioFile = audioFile;
		audioFile.addObserver(this);
		setChanged();
		notifyObservers("all");
	}
	
	public void saveAudioFile() throws Exception {
		audioFileServices.saveAudioFile(audioFile);
	}
	
	public void updateAudioFile() throws Exception {
		audioFileServices.updateAudioFile(audioFile);
	}


	public void update(Observable arg0, Object arg1) {
		setChanged();
		notifyObservers(arg1);
	}
	
	public String toString() {
		return audioFile.toString();
	}
}
